<?php   

/**********************************************************
  @Author: Mohannad El-Barachi
  @Copyright: ICORPA 2011
  Pledges Controller
  *********************************************************/
    
class PledgesController extends Zend_Controller_Action   
{   
	    function init()
	    {}
	    
	    function preDispatch() 
	    {}

	    public function indexAction()
	    {
	    	// Get the Pledge ID
	    	$pledge_id = $this->_request->getParam('pledge_id');
	    	
	    	if ($pledge_id)
	    	{
		    	// Start the Pledges object
		    	$Pledge = new Pledges();
		    	
		    	// Get the pledge's details
		    	$this->view->pledge_details = $Pledge->get_pledge_details($pledge_id);
		    	
		    	// Get the next pledge avalable ID
		    	$this->view->next_pledge = $Pledge->get_next_pledge($pledge_id);
	    	}
	    }
	    
	    public function validatedAction()
	    {
	   		// Get the Pledge ID
	    	$pledge_id = $this->_request->getParam('pledge_id');
	    	
	    	if ($pledge_id)
	    	{
		    	// Start the Pledges object
		    	$Pledge = new Pledges();
		    	
		    	// Get the pledge's details
		    	$this->view->pledge_details = $Pledge->get_pledge_details($pledge_id);
		    	
		    	// Get the next pledge avalable ID
		    	$this->view->next_pledge = $Pledge->get_next_pledge($pledge_id);
	    	}
	    }
	    
	 	public function allAction()
	    {
		    // Start the Pledges object
		    $Pledge = new Pledges();
		    
		    // Get the total number of pledge 
		    $total_pledges = $Pledge->get_pledges('count');
		    	
	    	// Get all the pledges divided into 2 columns
	    	$this->view->pledges_1 = $Pledge->get_pledges('all',0,round($total_pledges->count/2,0,PHP_ROUND_HALF_DOWN),'pledge_id','desc');
	    	$this->view->pledges_2 = $Pledge->get_pledges('all',round($total_pledges->count/2),round($total_pledges->count/2),'pledge_id','desc');
	    	
	    	// Get the total number of pledges
	    	$this->view->pledges_counter = $Pledge->get_pledge_counter(1);
	    	
	    	// Get the distinct number of countries
	    	$this->view->pledge_countries = $Pledge->get_distinct_countries();
	    	
	    	// Get the distinct number of areas of exptertise
	    	$this->view->pledge_fields = $Pledge->get_distinct_areas_of_expertise();
	    }
}

?>
